$(document).ready(function() {	
	$('.tipsy').tipsy({gravity: 'w'});// nw | n | ne | w | e | sw | s | se --- http://onehackoranother.com/projects/jquery/tipsy/	
	$("#frmCreate").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			pcategoryid:{
				required				: true,
				min						: 1
			},	
			psubcategoryid:{
				required				: true,
				min						: 1
			},	
			pname:{
				required				: true,
				minlength				: 5
			},
			pprovince:{
				required				: true,
				min						: 1
			},
			pdistrict:{
				required				: true,
				min						: 1
			},
			paddress:{
				required				: true,
				minlength				: 5
			},
			pimage: {
				required				: true,
				validateImgFormat		: true,
				validateImgSize			: true
			}/*,			
			pcontent: {
				validateContentRequired	: true,
				validateContentMinlength: true
			},
			pmap:{
				required				: true,
				minlength				: 20
			}*/
		},
		messages: {	
			pcategoryid:{
				required				: cate_required,
				min						: cate_required
			},	
			psubcategoryid:{
				required				: subcate_required,
				min						: subcate_required
			},	
			pname:{
				required				: name_required,
				minlength				: name_minlength
			},
			pprovince:{
				required				: province_required,
				min						: province_required
			},
			pdistrict:{
				required				: district_required,
				min						: district_required
			},
			paddress:{
				required				: address_required,
				minlength				: address_minlength
			},
			pimage: {
				required				: image_required,
				validateImgFormat		: image_format,
				validateImgSize			: image_size
			}/*,			
			pcontent: {
				validateContentRequired	: content_required,
				validateContentMinlength: content_minlength
			},
			pmap:{
				required				: map_required,
				minlength				: map_minlength
			}*/
		},
		errorPlacement: function(label, element) {
			var id = element.attr('id');	
			if(id == "pimage") {
				label.insertAfter($('#aimage'));					
			} else if(id == "pcontent") {			
				label.insertAfter($('#pcontent___Frame'));
			}
			else if(id == "psubcategoryid") {			
				label.insertAfter($('.category'));
			} else if(id == "pprovince") {			
				label.insertAfter($('.province'));
			} else if(id == "pdistrict") {			
				label.insertAfter($('.district'));
			} else {
				label.insertAfter($('#' + id));			
			}
			
		}				 
	});
	$.validator.addMethod('validateImgFormat', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return false;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validateImgSize', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return false;
		}
		return validateImgSize("pimage");
	});	
	$.validator.addMethod('validateContentRequired',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ), 1);		
		if(strContent == '')
			return false;		
		return true;												 
	});
	$.validator.addMethod('validateContentMinlength',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ), 1);		
		if(strContent != '' && strContent.length < 20)
			return false;		
		return true;												 
	});	
});
loadSub = function(intValue, strDiv) {
	$.getJSON(
		HOST_VFRIEND + 'ajax/subcate?type=11&parentid=' + intValue + '&callback=?',		
		function(response) {										
			$('#'+strDiv).html(response['data']);
		}
	);
}
loadDistrict = function(intValue, strDiv) {
	$.getJSON(
		HOST_VFRIEND + 'ajax/district?province=' + intValue + '&callback=?',		
		function(response) {							
			$('#'+strDiv).html(response['data']);
		}
	);
}
